package com.vca.admin.config;

import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * @author chenbing
 * @date 2022/6/30   13:31
 */
@Configuration
public class TaskScheduledLockConfig {
    @Bean
    public LockProvider lockProvider(@Qualifier("dataSource") DataSource dataSource) {
        // Works on Postgres, MySQL, MariaDb, MS SQL, Oracle, DB2, HSQL and H2
        return new JdbcTemplateLockProvider(
                JdbcTemplateLockProvider.Configuration.builder()
                        .withJdbcTemplate(new JdbcTemplate(dataSource))
//                        .usingDbTime()
                        .build()
        );
    }
}
